<template>
  <div class="wrapper">
    <div class="itemWrapper">
      <div class="imageWrapper">
        <img class="image" :src="product.small_image" alt="product.spec" />
      </div>
      <div class="name">{{ product.name }}</div>
      <div class="originPrice">{{ product.origin_price | moneyFormat}}</div>
      <div class="priceWrapper">
        <div class="price">{{ product.price | moneyFormat}}</div>
        <div class="iconCartWrapper glyphicon glyphicon-shopping-cart" @click="addToCart(product)"></div>
      </div>
    </div>
  </div>
</template>


<script>
import PubSub from "pubsub-js";
export default {
  name: "flashsaleitem",
  props: {
    product: Object
  },

  data() {
    return {};
  },
  methods: {
    addToCart(goods) {
      PubSub.publish("homeAddToCart", goods);
    }
  }
};
</script>


<style lang="less" scoped>
.wrapper {
  display: inline-block;
  // white-space: normal;
  padding: 0 0.3rem;
  margin: 0 0.5rem;
  width: 29%;

  @media screen and (min-width: 0px) and (max-width: 320px) {
    .itemWrapper {
      width: 33%;
    }
  }

  .itemWrapper {
    .image {
      // height: auto;
      width: 100%;
      margin-bottom: 1rem;

      // display: block;
    }
  }
  .name {
    font-size: 1.2rem;
    height: 3rem;
    line-height: 1.5rem;
    text-align: center;
    white-space: normal;
    margin-bottom: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .originPrice {
    text-decoration: line-through;
    color: #999;
  }

  .priceWrapper {
    // display: flex;
    // justify-content: space-between;
    position: relative;
    margin-bottom: 1rem;

    .price {
      position: absolute;
      top: 0.5rem;
      color: #fe6263;
    }

    .iconCartWrapper {
      position: absolute;
      top: -0.3rem;
      right: 0.1rem;
      padding: 0.5rem;
      color: #fff;
      background-color: #3cb963;
      border-radius: 50%;
    }
  }
}
</style>